﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calculator_Console
{
    public class Calculator
    {
        // 属性
        private double num1;
        private double num2;
        public double Num1 { get => num1; set => num1 = value; }
        public double Num2 { get => num2; set => num2 = value; }

        public Calculator()
        {
            Num1 = 0;
            Num2 = 0;
        }
        public Calculator(double num1, double num2)
        {
            Num1 = num1;
            Num2 = num2;
        }

        public double GetResult(string s)
        {
            double result = 0;
            switch(s)
            {
                case "+":result = Num1 + Num2;break;
                case "-":result = Num1 - Num2;break;
                case "*":result = Num1 * Num2;break;
                case "/":
                    if (Num2 == 0)
                        throw new Exception("除数不能为0！");
                    else
                        result = Num1 / Num2; break;
                default:break;
            }
            return result;
        }
        
    }
}
